<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>异步产生的bug</title>
    <script>
        async function fetchCount(id) {
            return 15 ;
        }
        var count1 = 0 ;
        async function addCount1(id) {
            count1 += await fetchCount(id);
            // 第1次输出 15
            // 第2次输出 15
            console.log("count1",count1)
        }
        var count2 = 0;
        async function addCount2(id) {
            var result = await fetchCount(id);
            count2 = count2+result;
            // 第1次输出 15
            // 第2次输出 30
            console.log("count2",count2)
        }

        addCount1(1);
        addCount1(2);

        addCount2(1);
        addCount2(2);
        // 输出 0
        console.log("count1",count1)
        // 输出 0
        console.log("count2",count2)

    </script>
</head>
<body>

</body>
</html>